import 'package:flutter/material.dart';
import 'package:flutter_rider/main/widgets/ui_constant.dart';
import 'package:flutter_rider/utils/screen_fit.dart';

class LoadingDialog {
  var _isShow = false;
  BuildContext _context;
  LoadingDialog(this._context);

  show({String text = ""}) {
    _isShow = true;
    showGeneralDialog(
      context: _context,
      barrierDismissible: false,
      pageBuilder: (context, animation, animation2) {
        return WillPopScope(
          onWillPop: () {
            return Future.value(false);
          },
          child: Align(
            child: Container(
              width: 120.rpx,
              height: 120.rpx,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10.rpx)),
              ),
              child: Center(
                child: Material(
                  color: UIColor.color_content,
                    child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    SizedBox(
                        width: 40.rpx,
                        height: 40.rpx,
                        child: const CircularProgressIndicator(
                          color: UIColor.color_primary,
                        )),
                    SizedBox(
                      height: 20.rpx,
                    ),
                    text.isNotEmpty
                        ? Text(
                            text,
                            style: TextStyle(
                                color: UIColor.color_t1, fontSize: 15.rpx),
                          )
                        : const SizedBox(),
                  ],
                )),
              ),
            ),
          ),
        );
      },
    );
  }

  hide() {
    if (_isShow) {
      Navigator.of(_context).pop();
      _isShow = false;
    }
  }
}